import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { BaseItem } from "../common/BaseItem";
import { HolidayReturnData } from "./HolidayReturnData";
import { EHolidayRetGiftBagStatus } from "../../../../Message/Public/EHolidayRetGiftBagStatus";
import { ItemData } from "../../resource/info/ItemData";
import { Language } from "../../../../extend/language/Language";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { FlyToNavbarTool } from "../award/FlyToNavbarTool";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Alert } from "../../../../com/mui/controls/Alert";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class HolidayReturnRender
    
    export  class HolidayReturnRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 80, 134, this, ImagesConst.RechargeBottom);
            this._nameBg = ObjCreate.createBg(4, 5, 73, 20, this, ImagesConst.FightingStrgBg);
            this._itemBg = ObjCreate.createBg(6, 28, 65, 65, this, ImagesConst.PackItemBg);
            this._nameTxt = ObjCreate.createTextField("", 1, 5, 78, 22, this, new GTextFormat(FontUtil.songtiName, 14, 15788607, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._item = new BaseItem();
            this._item.move(8, 30);
            this._item.setSize(60, 60);
            this._item.isDragAble = false;
            this._item.isDropAble = false;
            addChild(this._item);
            this._getBtn = ObjCreate.createGButton("", 9, 100, 60, 23, this, "ButtonRedMini");
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClick);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._holidayData = arg1 as HolidayReturnData;
            if (this._holidayData) 
            {
                this._item.filters = [];
                this._nameTxt.text = this._holidayData.tHolidayReturn.activeDt.getMonth() + 1 + "" + "." + this._holidayData.tHolidayReturn.activeDt.getDate();
                if (this._holidayData.btnStatus != EHolidayRetGiftBagStatus._EHolidayRetGiftBagUnavailable) 
                {
                    loc1 = new ItemData(this._holidayData.tHolidayReturn.giftBagCode);
                    if (loc1 && !(loc1 == ItemData.nullItemData)) 
                    {
                        this._item.itemData = loc1;
                    }
                    else 
                    {
                        this._item.itemData = null;
                    }
                    this.showQuestionBmp(false);
                }
                else 
                {
                    this.showQuestionBmp();
                }
                if (this._holidayData.btnStatus != EHolidayRetGiftBagStatus._EHolidayRetGiftBagUnavailable) 
                {
                    if (this._holidayData.btnStatus != EHolidayRetGiftBagStatus._EHolidayRetGiftBagAvailable) 
                    {
                        if (this._holidayData.btnStatus != EHolidayRetGiftBagStatus._EHolidayRetGiftBagHadGot) 
                        {
                            if (this._holidayData.btnStatus == EHolidayRetGiftBagStatus._EHolidayRetGiftBagMakeUpByGold) 
                            {
                                this._getBtn.label = Language.getString(74008);
                                this._getBtn.enabled = true;
                                this._getBtn.filters = [];
                            }
                        }
                        else 
                        {
                            this._getBtn.label = Language.getString(74006);
                            this._getBtn.enabled = false;
                            this._getBtn.filters = [FilterConst.colorFilter];
                            this._item.filters = [FilterConst.colorFilter];
                        }
                    }
                    else 
                    {
                        this._getBtn.label = Language.getString(74005);
                        this._getBtn.enabled = true;
                        this._getBtn.filters = [];
                    }
                }
                else 
                {
                    this._getBtn.label = Language.getString(74004);
                    this._getBtn.enabled = false;
                    this._getBtn.filters = [FilterConst.colorFilter];
                }
                this._getBtn.drawNow();
                if (this._holidayData.isFly) 
                {
                    this._holidayData.isFly = false;
                    FlyToNavbarTool.flyToBackPack(this._item.bitmapdata, localToGlobal(new Object /* flash.geom.Point */(this._item.x, this._item.y)));
                }
            }
            else 
            {
                this._nameTxt.text = "";
                this._item.itemData = null;
            }
            return;
        }

        /* internal  */onGetBtnClick(arg1: Object /* flash.events.Event */): void
        {
            if (this._holidayData.btnStatus != EHolidayRetGiftBagStatus._EHolidayRetGiftBagMakeUpByGold) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.HolidayReturnGetGifBag, this._holidayData.tHolidayReturn.id));
            }
            else 
            {
                Alert.show(Language.getString(74009), null, Alert.OK | Alert.CANCEL, null, this.onAlertConfir);
            }
            return;
        }

        /* internal  */onAlertConfir(arg1: int): void
        {
            if (arg1 == Alert.OK) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.HolidayReturnGetGifBag, this._holidayData.tHolidayReturn.id));
            }
            return;
        }

        /* internal  */showQuestionBmp(arg1: Boolean=true): void
        {
            if (this._questionBmp == null) 
            {
                this._questionBmp = new Object /* flash.display.Bitmap */();
                this._questionBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.QuestionItem);
            }
            if (arg1) 
            {
                this.addChild(this._questionBmp);
                this._questionBmp.x = 8;
                this._questionBmp.y = 30;
            }
            else if (this._questionBmp.parent) 
            {
                this._questionBmp.parent.removeChild(this._questionBmp);
            }
            return;
        }

        public flyPack(): void
        {
            FlyToNavbarTool.flyToBackPack(this._item.bitmapdata, localToGlobal(new Object /* flash.geom.Point */(this._item.x, this._item.y)));
            return;
        }

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_questionBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameBg: ScaleBitmap;

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_item: BaseItem;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_holidayData: HolidayReturnData;
    }
